<%@ page language="java" contentType="text/xml; charset=UTF-8"
    pageEncoding="UTF-8" import="database.DAO, golf.ChatMsg"%>


<% 
	DAO dao = DAO.getInstance();
	ChatMsg[] msgs = null;
	ChatMsg msgInfo = new ChatMsg();
	
	msgInfo.setRoomNo(Integer.parseInt(session.getAttribute("roomNo").toString()));
	msgInfo.setChatNo(Integer.parseInt(request.getParameter("lastid").toString()));
	msgInfo.setServerNo(Integer.parseInt(session.getAttribute("serverNo").toString()));
	msgInfo.setSenderNo(Integer.parseInt(session.getAttribute("charNo").toString()));
	if(request.getAttribute("toWho") != null) {
		msgInfo.setRecvName(request.getAttribute("toWho").toString());
	} else {
		msgInfo.setRecvName("null");
	}
	if(session.getAttribute("guildNo") != null) {
		msgInfo.setGuildNo(Integer.parseInt(session.getAttribute("guildNo").toString()));
	} else {
		msgInfo.setGuildNo(-1);
	}
	msgInfo.setSenderNo(Integer.parseInt(session.getAttribute("charNo").toString()));
	
	msgs = dao.getChatMsg(msgInfo);
	out.println("<messages>");
	//System.out.println("<messages>");
	if(msgs != null) {
		String xmls = "";
		for(int i = 0; i < msgs.length; i++ ) {
			xmls = "";
			xmls += "<message id=\"" + String.valueOf(msgs[i].getChatNo()) + "\"";
			xmls += " serverNo=\"" + String.valueOf(msgs[i].getServerNo()) + "\"";
			xmls += " senderCharNo=\"" + String.valueOf(msgs[i].getSenderNo()) + "\"";
			xmls += " senderName=\"" + msgs[i].getSenderName() + "\"";
			xmls += " chatCdClassify=\"" + msgs[i].getChatCdClassify() + "\"";
			xmls += " chatCD=\"" + msgs[i].getChatCd() +"\">";
			xmls += msgs[i].getChatContent() + "</message>";
			out.println(xmls);
			//System.out.println(xmls);	//for debuging
		}
	}
	out.println("</messages>");
	//System.out.println("</messages>");//for debuging
%>